#!/bin/bash

# 项目部署脚本

echo "=========================================="
echo "开始部署数据同步服务"
echo "=========================================="

# 项目配置
APP_NAME="data-sync-task"
APP_VERSION="1.0.0"
JAR_NAME="${APP_NAME}-${APP_VERSION}.jar"
DEPLOY_DIR="/app/data-sync"

# 1. 编译打包
echo "1. 开始Maven打包..."
mvn clean package -DskipTests

if [ $? -ne 0 ]; then
    echo "❌ Maven打包失败！"
    exit 1
fi
echo "✅ Maven打包成功"

# 2. 创建部署目录
echo "2. 创建部署目录..."
mkdir -p $DEPLOY_DIR/logs
mkdir -p $DEPLOY_DIR/config

# 3. 复制JAR包
echo "3. 复制JAR包到部署目录..."
cp target/${JAR_NAME} $DEPLOY_DIR/

# 4. 复制配置文件
echo "4. 复制配置文件..."
cp application.yml $DEPLOY_DIR/config/

# 5. 复制启动脚本
echo "5. 复制启动脚本..."
cp scripts/start.sh $DEPLOY_DIR/
cp scripts/stop.sh $DEPLOY_DIR/
chmod +x $DEPLOY_DIR/*.sh

# 6. 初始化数据同步目录
echo "6. 初始化数据同步目录..."
bash scripts/init-directories.sh

echo "=========================================="
echo "✅ 部署完成！"
echo "=========================================="
echo "部署目录: $DEPLOY_DIR"
echo "启动命令: cd $DEPLOY_DIR && ./start.sh"
echo "停止命令: cd $DEPLOY_DIR && ./stop.sh"
echo "=========================================="
